#include <stdio.h>
#include "memory/memory_pool.h"
#include <unistd.h>

struct  my_data
{
    char data[1024*64];
};
struct free_node_t2 {
    struct  my_data data;
	struct list_head entry;
};

int main(int argc, char **argv) {
    printf("%d, %d, %d\n", sizeof(struct free_node_t2), sizeof(struct free_node_t), sizeof(struct  my_data));

    printf("===============>0\n");
    sleep(15);
    int n = 20;
    do {
        struct memory_pool_t *pool = memory_pool_create(sizeof(struct my_data), 20);
        struct my_data *arr[400] = { 0x00 };
        for (int i = 0;i < 100;i++) {
            arr[i] = (struct my_data *)memory_pool_malloc(pool);
            snprintf(arr[i]->data, sizeof(arr[i]->data), "data %d", i);
            // printf("%d data = %p\n", i, arr[i]);
        }

        for (int i = 0;i < 100;i++) {
            memory_pool_free(pool, arr[i]);
        }
        printf("===============>100\n");
        for (int i = 0;i < 200;i++) {
            arr[i] = (struct my_data *)memory_pool_malloc(pool);
            snprintf(arr[i]->data, sizeof(arr[i]->data), "data %d", i);
            // printf("%d data = %p\n", i, arr[i]);
        }

        for (int i = 0;i < 200;i++) {
            memory_pool_free(pool, arr[i]);
        }
        printf("===============>200\n");
        for (int i = 0;i < 400;i++) {
            arr[i] = (struct my_data *)memory_pool_malloc(pool);
            snprintf(arr[i]->data, sizeof(arr[i]->data), "data %d", i);
            // printf("%d data = %p\n", i, arr[i]);
        }
        for (int i = 0;i < 400;i++) {
            memory_pool_free(pool, arr[i]);
        }
        printf("===============>400\n");
        memory_pool_destroy(pool);
        sleep(1);
    } while(n-- > 0);
    printf("===============> exit;\n");
    sleep(10);
    return 0;
}